/*
 * zmenu.c
 *
 *  Created on: 24 avr. 2012
 *      Author: Florian.B
 */

#include "zmenu.h"
#include "zserver.h"
void addNewServer_ZMenu(GtkMenuItem *menuitem, gpointer user_data)
    {
    ZContainer *zContainer = user_data;
    GtkWidget *dialog, *label, *contentArea;
    GtkWidget *vbox, *hbox;
    GtkWidget *labelPort, *entryPort;
    GtkWidget *labelHost, *entryHost;
    GtkWidget *labelNom, *entryNom;
    const gchar *nom, *host, *port;
    dialog = gtk_dialog_new_with_buttons("Server", NULL, GTK_DIALOG_MODAL,
	    GTK_STOCK_OK, GTK_RESPONSE_ACCEPT, GTK_STOCK_CANCEL,
	    GTK_RESPONSE_REJECT, NULL);
    contentArea = gtk_dialog_get_content_area(GTK_DIALOG(dialog));
    label = gtk_label_new("Enregistrement d'un nouveau serveur");

    vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 1);
    gtk_container_add(GTK_CONTAINER(contentArea), vbox);
    gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 1);

    hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 1);
    gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 1);
    labelNom = gtk_label_new("Nom du server (optionnel)");
    gtk_box_pack_start(GTK_BOX(hbox), labelNom, FALSE, FALSE, 1);
    entryNom = gtk_entry_new();
    gtk_box_pack_start(GTK_BOX(hbox), entryNom, TRUE, TRUE, 1);

    hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 1);
    gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 1);
    labelHost = gtk_label_new("Server");
    gtk_box_pack_start(GTK_BOX(hbox), labelHost, FALSE, FALSE, 1);
    entryHost = gtk_entry_new();
    gtk_box_pack_start(GTK_BOX(hbox), entryHost, TRUE, TRUE, 1);

    hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 1);
    gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 1);
    labelPort = gtk_label_new("Port");
    gtk_box_pack_start(GTK_BOX(hbox), labelPort, FALSE, FALSE, 1);
    entryPort = gtk_entry_new();
    gtk_box_pack_start(GTK_BOX(hbox), entryPort, TRUE, TRUE, 1);
    gtk_widget_show_all(dialog);
    switch (gtk_dialog_run(GTK_DIALOG(dialog)))
	{
    case GTK_RESPONSE_ACCEPT:
	nom = gtk_entry_get_text(GTK_ENTRY(entryNom));
	host = gtk_entry_get_text(GTK_ENTRY(entryHost));
	port = gtk_entry_get_text(GTK_ENTRY(entryPort));
	addServer_ZServer(getZServer_ZContainer(zContainer), nom, host, port);
	break;
    case GTK_RESPONSE_REJECT:
	break;
    default:
	break;
	}
    gtk_widget_destroy(dialog);
    (void) menuitem;
    }

GtkWidget *createMenu_Menu(ZContainer *zContainer)
    {
    GtkWidget *menu;

    GtkWidget *menuFichier, *menuItemFichier, *subFermer;
    GtkWidget *menuEdition, *menuItemEdition, *subNouveaux;
    GtkWidget *menuAffichage, *menuItemAffichage, *subCacher;
    GtkWidget *menuAide, *menuItemAide;

    menu = gtk_menu_bar_new();

    menuFichier = gtk_menu_new();
    menuEdition = gtk_menu_new();
    menuAffichage = gtk_menu_new();
    menuAide = gtk_menu_new();
    menuItemFichier = gtk_menu_item_new_with_label("Fichier");
    menuItemEdition = gtk_menu_item_new_with_label("Edition");
    menuItemAffichage = gtk_menu_item_new_with_label("Affichage");
    menuItemAide = gtk_menu_item_new_with_label("Aide");
    subFermer = gtk_image_menu_item_new_from_stock(GTK_STOCK_CLOSE, NULL);
    subNouveaux = gtk_image_menu_item_new_from_stock(GTK_STOCK_ADD, NULL);

    subCacher = gtk_image_menu_item_new_from_stock(GTK_STOCK_INFO, NULL);

    gtk_menu_shell_append(GTK_MENU_SHELL(menuFichier), subFermer);

    gtk_menu_shell_append(GTK_MENU_SHELL(menuEdition), subNouveaux);

    gtk_menu_shell_append(GTK_MENU_SHELL(menuAffichage), subCacher);
    gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuItemFichier);
    gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuItemEdition);
    gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuItemAffichage);

    gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuItemAide);

    gtk_menu_item_set_submenu(GTK_MENU_ITEM(menuItemFichier), menuFichier);
    gtk_menu_item_set_submenu(GTK_MENU_ITEM(menuItemEdition), menuEdition);
    gtk_menu_item_set_submenu(GTK_MENU_ITEM(menuItemAffichage), menuAffichage);

    gtk_menu_item_set_submenu(GTK_MENU_ITEM(menuItemAide), menuAide);

    g_signal_connect(subNouveaux, "activate", G_CALLBACK(addNewServer_ZMenu),
	    zContainer);
    return menu;

    }
